<?php
  require_once("includes/config.php"); 
  if($_SERVER["REQUEST_METHOD"] == "POST")
  {
    if(!empty($_POST['company_id']))
      $client_id = $_POST['company_id'];
    else
      $client_id = $_POST['client_id'];
      
    
      
    $result = query("INSERT INTO contracts 
          (client_id, apartment_id,period, rent_type, mildai_from,miladi_out ,hijri_in,hijri_out,total,discount,owner_id,related_company,chosen_weekly,chosen_daily,chosen_monthly,contract_status,company_id) 
      VALUES 
          (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
          
      $client_id,$_POST['apartment_id'],$_POST['period'],$_POST['rent_type'],$_POST['from'],$_POST['to'],$_POST['hijri-from'],$_POST['hijri-to'],$_POST['final-price'],$_POST['discount'],$_SESSION['user_id'],$_POST['company_name']
      ,$_POST['weekly_price'],$_POST['daily_price'],$_POST['monthly_price'],$_POST['what-button'],$_POST['company_id']);
      $_SESSION['success_message'] = "تم إضافة العقد بنجاح"; 
      
      if($_POST['what-button'] == 2)
        $status = 1;
      else
        $status = 6;
        
      $result = query("UPDATE apartments SET status=? where id=?",$status,$_POST['apartment_id']);
      redirect("bookings.php");   
      

 }
	?>